package com.sc.admin.controller;

import com.sc.admin.common.enums.BusinessTypeEnum;
import com.sc.admin.common.enums.ModuleEnum;
import com.sc.admin.common.model.Option;
import com.sc.admin.common.result.Result;
import com.sc.admin.common.util.IpUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

@Tag(name = "09.公共接口")
@RestController
@RequestMapping("/api/v1/common")
@RequiredArgsConstructor
public class CommonController {

    @Operation(summary = "获取模块下拉列表")
    @GetMapping("/modules")
    public Result<List<Option<String>>> getAllModules() {
        List<Option<String>> list = Arrays.stream(ModuleEnum.values()).map(obj -> new Option<>(obj.name(), obj.name)).toList();
        return Result.success(list);
    }

    @Operation(summary = "获取业务类型下拉列表")
    @GetMapping("/businessTypes")
    public Result<List<Option<String>>> getBizTypes() {
        List<Option<String>> list = Arrays.stream(BusinessTypeEnum.values()).map(obj -> new Option<>(obj.type, obj.type)).toList();
        return Result.success(list);
    }

    @Operation(summary = "获取ipv4地址")
    @GetMapping("/ipv4")
    public Result<String> getIpv4() {
        return Result.success(IpUtils.getIpAddr());
    }


}
